package com.qfedu.yanglao20admin.sysAdmin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qfedu.yanglao20.common.CommonResult;
import com.qfedu.yanglao20admin.sysAdmin.param.SysUserParam;
import com.qfedu.yanglao20admin.sysAdmin.service.SysUserService;
import com.qfedu.yanglao20admin.sysAdmin.vo.SysUserPasswordVO;
import com.qfedu.yanglao20admin.sysAdmin.vo.SysUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "用户管理信息")
@RestController
@RequestMapping("/sysUser")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    @ApiOperation(value = "查询所有用户管理信息", notes = "查询所有用户管理信息")
    @GetMapping("/all")
    public CommonResult queryAllCameraList() {
        List<SysUserVO> sysUserVOS = sysUserService.selectListAll();
        return CommonResult.success(sysUserVOS);
    }

    @ApiOperation(value = "根据id删除用户管理信息", notes = "根据id删除用户管理信息")
    @GetMapping("/delete")
    public CommonResult deleteSysUserList(@RequestParam @ApiParam("用户管理信息id") Integer id) {
        sysUserService.deleteById(id);
        return CommonResult.success();
    }

    @ApiOperation(value = "分页展示用户管理信息", notes = "分页展示用户管理信息")
    @GetMapping("/list")
    public CommonResult<SysUserParam> SysUserList(SysUserParam param) {
        Page<SysUserVO> sysUserVOPage = sysUserService.pageSysUserList(param);
        return CommonResult.success(sysUserVOPage);
    }

    @ApiOperation(value = "添加用户管理信息", notes = "添加用户管理信息")
    @PostMapping("/add")
    public CommonResult<SysUserVO> addSysUserList(SysUserVO sysUserVO) {
        sysUserService.add(sysUserVO);
        return CommonResult.success();
    }

    @ApiOperation(value = "根据id查询用户管理信息", notes = "根据id查询用户管理信息")
    @GetMapping("/query")
    public CommonResult querySysUserList(@RequestParam @ApiParam("用户管理信息id") Integer id) {
        SysUserVO sysUserVO = sysUserService.selectById(id);
        return CommonResult.success(sysUserVO);
    }

    @ApiOperation(value = "修改用户管理信息", notes = "修改用户管理信息")
    @PostMapping("/update")
    public CommonResult<SysUserVO> updateSysUserList(SysUserVO sysUserVO) {
        sysUserService.update(sysUserVO);
        return CommonResult.success();
    }

    @ApiOperation(value = "重置密码", notes = "重置密码")
    @PostMapping("/updatePassword")
    public CommonResult<SysUserPasswordVO> updatePassword(SysUserPasswordVO passwordVO) {
        sysUserService.updatePassword(passwordVO);
        return CommonResult.success();
    }
}
